
var app = getApp()
Page({
  onPullDownRefresh(){
    wx.showNavigationBarLoading()
    this.refresh();
    console.log("upper");
    setTimeout(function () { wx.hideNavigationBarLoading(); wx.stopPullDownRefresh(); }, 2000);
  },
  data: {
    feed: [],
    feed_length: 0,
    searchUrl:"../../image/search.png",
    editUrl:"../../image/edit.png",
    jsonresult: '',
    sourceUrl:'https://eis.natappvip.cc/ITSupport',
    searchContent:"",
    selectArray: ['标题', '类型'],
    selectId: 0
  },
  //事件处理函数
  bindItemTap: function (e) {
    var $topicId = e.currentTarget.dataset.topicId
    wx.navigateTo({
      url: '../topic/topic?topicId=' + $topicId
    })
  },

  bindSelectChange:function(e){
    this.setData({
      selectId: e.detail.value
    })
  },

  edit: function () {
    wx.navigateTo({
      url: '../edit/edit'
    })
  },
  onLoad: function () {
    console.log('onLoad')
    //调用应用实例的方法获取全局数据
    this.refresh();
  },
  
  onShow: function () {
    this.refresh()
  },

  searchInput: function (e) {
    this.setData({
      searchContent: e.detail.value
    })
  },

  search: function () {
    if (this.data.searchContent != ""){
      wx.navigateTo({
        url: '../search/search?searchContent=' + this.data.searchContent + '&selectId=' + this.data.selectId
      })
    }
  },

  //网络请求数据, 实现首页刷新
  refresh: function () {
    var that = this
    wx.request({
      url: 'https://eis.natappvip.cc/ITSupport/topic_getAllTopics.action',
      data: {},
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        let jsonresult = JSON.parse(res.data)
        console.log(jsonresult.result)
        if (jsonresult.result == "error") {
          that.setData({
            message: "页面空空如也~"
          })
        } else {
        that.setData({
          feed: jsonresult.topics,
          feed_length: jsonresult.topics.length
        })
        console.log("success")
        }
      },
      fail: function (res) {
        console.log("failed:" & res)
      }
    })
  },
  
})
